﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
using TrackSystem.Entities.Extensions;

namespace TrackSystem.Entities.Models
{
    /// <summary>
    /// 服务器数据表定义
    /// </summary>
    [Table("slave")]
    public class SlaveTable
    {
        /// <summary>
        /// 统一标识符
        /// </summary>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Name = "统一标识符")]
        public int Id { get; set; }
        /// <summary>
        /// 通道名称
        /// </summary>
        [Required]
        [Display(Name = "服务器名称")]
        public required string Name { get; set; }
        /// <summary>
        /// 通道描述
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// 协议类型
        /// </summary>
        public SlaveProtocol Protocol { get; set; }
        /// <summary>
        /// 端口类型
        /// </summary>
        public PortCategory PortCategory { get; set; }
        /// <summary>
        /// 远程IP地址
        /// </summary>
        public string RemoteIP { get; set; }
        /// <summary>
        /// 远程端口地址
        /// </summary>
        public int RemotePort { get; set; }
        /// <summary>
        /// 本地IP地址
        /// </summary>
        public string LocalIP { get; set; }
        /// <summary>
        /// 本地端口地址
        /// </summary>
        public int LocalPort { get; set; }
        /// <summary>
        /// 串口号
        /// </summary>
        public string Comx { get; set; }
        /// <summary>
        /// 波特率
        /// </summary>
        public int BaudRate { get; set; }
        /// <summary>
        /// 串口参数
        /// </summary>
        public string SerialParams { get; set; }
        /// <summary>
        /// 站地址
        /// </summary>
        public int Station { get; set; }
        /// <summary>
        /// 只读寄存器列表
        /// </summary>
        public string RoList { get; set; }
        /// <summary>
        /// 读写寄存器列表
        /// </summary>
        public string RwList { get; set; }
        /// <summary>
        /// udp方式下的通信帧
        /// </summary>
        public string ProtocolDefine { get; set; }
        /// <summary>
        /// udp方式下间隔时间ms
        /// </summary>
        public int Cycle { get; set; }
    }

    /// <summary>
    /// 服务器种类
    /// </summary>
    public enum SlaveProtocol
    {
        /// <summary>
        /// modbus服务器 TCP/IP方式下的modbus
        /// </summary>
        Modbus_RTU = 0,
        
        /// <summary>
        /// 
        /// </summary>
        Modbus_TCP,
        
        /// <summary>
        /// 用户自定义
        /// </summary>
        USERDEFINED,
    }
}
